<?php
session_start();

$adminEmail = $_SESSION['admin_email'];
unset($_SESSION['admin_email']);
unset($_SESSION['admin_name']);

echo '登出成功。<a href="index.php?c=login">前往登录页</a>';

$log = [
    'action' => 'admin_logout',
    'content' => '登出后台成功',
    'time' => date("Y-m-d H:i:s", time()),
    'ip' => $_SERVER['REMOTE_ADDR'],
    'admin_email' => $adminEmail,
];
$file = fopen("./logs/" . date("Y-m-d") . ".txt", 'a+');
if ($file) {
    fwrite($file, json_encode($log, JSON_UNESCAPED_UNICODE) . PHP_EOL);
    fclose($file);
} else {
    echo "打开文件错误";
    exit();
}
